/**
 * Notes: Admin初始化控制器
 * Date: 2024-01-01 00:00:00
 */

const BaseController = require('./base_controller.js');
const AdminInitService = require('../service/admin_init_service.js');

class AdminInitController extends BaseController {

    /**
     * 初始化admin账号
     */
    async initAdmin() {
        try {
            const service = new AdminInitService();
            const result = await service.initAdminAccount();
            
            return this.success(result);
        } catch (error) {
            return this.fail(error.message);
        }
    }

    /**
     * 检查admin账号状态
     */
    async checkAdminStatus() {
        try {
            const AdminModel = require('../model/admin_model.js');
            
            // 检查admin账号是否存在且状态正常
            const admin = await AdminModel.getOne({}, 'ADMIN_ID,ADMIN_NAME,ADMIN_STATUS,ADMIN_TYPE');
            
            if (!admin) {
                return this.success({
                    exists: false,
                    message: 'admin账号不存在'
                });
            }
            
            return this.success({
                exists: true,
                status: admin.ADMIN_STATUS,
                type: admin.ADMIN_TYPE,
                message: admin.ADMIN_STATUS === 1 ? 'admin账号状态正常' : 'admin账号已禁用'
            });
            
        } catch (error) {
            return this.fail(error.message);
        }
    }
}

module.exports = AdminInitController;
